<template>
  <div class="wfull">
    <a-form :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }">
      <a-form-item label="角色名称" required>
        <ZgInput v-model="obj.name"></ZgInput>
      </a-form-item>
      <a-form-item label="角色编码" required>
        <ZgInput v-model="obj.code"></ZgInput>
      </a-form-item>
    </a-form>
  </div>
</template>
<script>
export default {
  props: {
    jsonStr: {
      type: String,
      default: null
    }
  },
  data () {
    return {
      obj: {
        roleId: '',
        name: '',
        code: ''
      }
    }
  },
  watch: {
    jsonStr () {
      this.init()
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    init () {
      if (this.jsonStr && this.jsonStr.length > 0) {
        this.obj = JSON.parse(this.jsonStr)
        this.obj.roleId = this.obj.id
      }
    },
    save () {
      if (this.obj.name.length === 0) {
        return this.$result.error('请输入字典名称')
      }
      if (this.obj.code.length === 0) {
        return this.$result.error('请输入字典编码')
      }
      return this.$result.ok(Object.assign({}, this.obj))
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
